using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;

namespace FederationMembershipDB
{
	public class Product
	{
        int _productId;
        string _name;
		double _priceExGST;
        int _qty;

        public int ProductNumber
        { get { return _productId; } set { _productId = value; } }
        public string ProductName
        {
            get { return _name; }
            set { _name = value; }
        }

        public double PriceExGST
        {
            get { return _priceExGST; }
            set { _priceExGST = value; }
        }

        public int Quantity
        {
            get { return _qty; }
            set { _qty = value; }
        }
		public void AddProduct(int p_productId, string p_name, double p_priceExtGST)
		{
            _productId = p_productId; //TODO: check the product doesn't already exist
            _name = p_name;
            _priceExGST = p_priceExtGST;

            //Add to database
            Utilities.openDatabase();

            SqlCommand addproduct = new SqlCommand(string.Format("INSERT INTO Product(ID, Name, PriceExGST) VALUES({0}, '{1}', ${2})", _productId, _name, _priceExGST), Utilities.connection);
            addproduct.ExecuteNonQuery();
            Utilities.connection.Close();
		}

		public void ViewProduct()
		{
			throw new NotImplementedException();
		}

        public void UpdateProduct(int p_productId, string p_name, double p_priceExtGST)
		{
            _productId = p_productId;
            _name = p_name;
            _priceExGST = p_priceExtGST;

            //Add to database
            Utilities.openDatabase();

            SqlCommand editproduct = new SqlCommand(string.Format("UPDATE Product SET Name = '{0}', PriceExGST = ${1} WHERE ID = {2}", _name, _priceExGST, _productId), Utilities.connection);
            editproduct.ExecuteNonQuery();
            Utilities.connection.Close();
		}

	}
}
